package org.publiccms.controller.web.sys;

import org.publiccms.mybatis.baseUtil.BaseResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Jintao_Ma on 2017/10/1.
 * 系统主界面Controller
 */
@Controller
@RequestMapping("main")
public class MainController {

    /**
     * 1.当返回的是界面
     */
    @RequestMapping(value = "changePassword", method = RequestMethod.POST)
    public ModelAndView returnPage(){
        ModelAndView mv = new ModelAndView();
        Map<String,Object> map = new HashMap<>();
        List<String> list = new ArrayList<>();
        mv.setViewName("page1");
        mv.addObject("map",map);
        mv.addObject("list",list);
        return mv;
    }

    /**
     * 2.当返回的是数据
     */
    @ResponseBody
    @RequestMapping(value = "changePassword", method = RequestMethod.POST)
    public BaseResult returnValue(){
        BaseResult baseResult = new BaseResult();
        try {
            Map<String,Object> map = new HashMap<>();
            List<Map<String,Object>> list = new ArrayList<>();

            baseResult.setSuccess(true);
            baseResult.setCode("200");
            baseResult.setMap(map);
            baseResult.setMapList(list);
        } catch (Exception e) {
            baseResult.setSuccess(false);
            baseResult.setCode("404");
            e.printStackTrace();
        }

        return baseResult;
    }

}
